package com.java2110.service.impl;

import com.java2110.dto.OptionsDTO;
import com.java2110.entity.Options;
import com.java2110.entity.Subjects;
import com.java2110.mapper.OptionsMapper;
import com.java2110.service.OptionsService;
import com.java2110.service.SubjectService;
import com.java2110.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author admin
 * @since 2025-05-2025/5/23 14:07
 */
@Service
@Transactional
public class OptionsServiceImpl implements OptionsService {
    @Autowired
    private OptionsMapper optionsMapper;
    @Autowired
    private SubjectService subjectService;
    @Override
    public PageUtils<Options> find(OptionsDTO optionsDTO) {
        PageUtils<Options> pageUtils = new PageUtils<>();
        Integer startIndexNo = (optionsDTO.getStartPageNo() - 1) * optionsDTO.getPageSize();
        optionsDTO.setStartIndexNo(startIndexNo);
        Integer count = optionsMapper.count();
        List<Options> data = optionsMapper.find(optionsDTO);
        pageUtils.setTotalCount(count);
        pageUtils.setData(data);
        pageUtils.setCurrentPageNo(optionsDTO.getStartPageNo());
        pageUtils.setPageSize(optionsDTO.getPageSize());
        return pageUtils;
    }

    @Override
    public Integer count() {
        return optionsMapper.count();
    }

    @Override
    public List<Options> findById(Integer id) {
        List<Options> optionsList = optionsMapper.findById(id);
        Integer result = subjectService.update(id);
        return optionsList;
    }
}
